// 1. 求字符串中各个字符出现的次数 
// reduce的用法  
const str = 'jordanbryantjamescurrydurant';
const res1 = str.split('').reduce((pre,cur) => {
    pre[cur] ? pre[cur]++ : pre[cur] = 1;  
    return pre;
},{})   
console.log(res1)   

// map  (key:value)  
const res = str.split('');
console.log(res,'////')  
// Map对象  
function search1(res) {
    const map = new Map();
    for(let i = 0; i< res.length;i++) {
        if(map.has(res[i])){
            map.set(res[i],map.get(res[i])+1)
        }else{
            map.set(res[i],1)
        }
    }
    return map;
}

function search(res) {
    const map = {};
    for(let i = 0; i< res.length;i++) {
        if(map[res[i]]){
            map[res[i] ]++
        }else{
            map[res[i] ] = 1 ;
        }
    }
    return map;
}
console.log(search(res))  //  

// Promise.all     
const p1 = new Promise((resolve,reject) => {
    setTimeout(() => {
        console.log('p1延迟一秒');
    },1000)
})
const p2 = new Promise((resolve,reject) => {
    setTimeout(() => {
        console.log('p2延迟一秒');
    },2000)
})
const p3 = new Promise((resolve,reject) => {
    setTimeout(() => {
        console.log('p3延迟一秒');
    },3000)
})   
length 
Promise.Myall = (promises) => {
    let arr = [];
    count = 0;
    return new Promise((resolve,reject) => {
        promises.forEach((item,i) => {
            Promise.resolve(item)   
                .then(res => {
                    arr[i] = res;
                    count += 1;
                    if(count == promises.length){
                        resolve(arr)
                    }
                },reject)
        })
    })
}



